package com.hjh.java.rabbitmq.controller;

import com.hjh.java.rabbitmq.bean.form.SendForm1;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rabbitmq")
public class RabbitmqController {

    @PostMapping("/test1")
    public String test1(){
        return "test1";
    }

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @PostMapping("/send1")
    public String send1(@RequestBody SendForm1 form1){

        String exchange ="exchange.name.import";
        String routingKey = "routingKey.name.import";
         rabbitTemplate.convertAndSend(exchange,routingKey,form1.getMessage());
        return "test1";
    }
}
